<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('修改【请填写功能名称】')" />
</head>
<style>
    .coursenum{
        border: none;
        background: none;
        width:30px;
    }
</style>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId" name="formId" action="" method="post" th:object="${tbPlanMain}">
                <div class="select-list">
                    <ul>
                        <li>
                            <input type="text" name="id" id="planId" th:value="${tbPlanMain.id}" hidden/>
                        </li>
                        <li>
                            <p>计划名称：</p>
                            <input type="text" name="planName" id="planName" th:value="${tbPlanMain.planName}"/>
                        </li>
                        <li>
                            <p>专业：</p>
                            <select name="majorId" id="majorId" th:with="type=${@dict.getType('sys_profession')}" onchange="$.table.search()">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>

                        <li>
                            <p>版本：</p>
                            <input type="text" name="version" id="version" th:value="${tbPlanMain.version}"/>
                        </li>
                        <li class="select-time">
                            <p>生效时间：</p>
                            <input type="text" style="width:58%" class="time-input" id="beginEffectiveTime" placeholder="生效时间" name="beginEffectiveTime" th:value="${#dates.format(tbPlanMain.effectiveTime,'yyyy-MM-dd')}"  data-format="yyyy-MM-dd"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="submitHandler()"><i class="fa fa-search"></i>&nbsp;保存</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.modal.reload()"><i class="fa fa-refresh"></i>&nbsp;取消</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <form id="commitForm">
                <table id="bootstrap-table">

                </table>
            </form>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:main:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:main:remove')}]];
    var prefix = ctx + "website/trainplan";

    $(function() {
        var options = {
            url: prefix + "/arrList/"+$("#planId").val(),
            modalName: "培养计划",
            columns: [{
                filed:'code',
                title:'已有课程',
                formatter: function (value, row, index) {
                    //console.log(row.code)
                    if(row.code==1){
                        return "<input type='checkbox' checked name='code'>";
                    }else{
                        return "<input type='checkbox' name='code'>";
                    }
                }
            },
                {
                    field : 'id',
                    title : '序号',
                    visible: true,
                    formatter: function (value, row, index) {
                        return "<input name='id'  type='hidden' value='"+row.id+"'><input class=\"coursenum\" name='id' type='text' onfocus=this.blur() value='"+value+"'>";
                    }
                },
                {
                    field : 'courseCode',
                    title : '课程编号',
                    formatter: function (value, row, index) {
                        return "<input name='courseId'  type='hidden' value='"+row.courseCode+"'><input class=\"coursenum\" name='courseCode' type='text' onfocus=this.blur() value='"+value+"'>";
                    }
                },
                {
                    field : 'courseName',
                    title : '课程名称'
                },
                {
                    field : 'chooseCourseType',
                    title : '选课类型',
                    formatter: function (value, row, index) {
                        console.log("111"+value);
                        if(row.chooseCourseType==0){
                            return "<select name=\"chooseCourseType\" class=\"form-control m-b\" style=\"width:100px;\" ><option value='0' selected>必修课</option><option value='1'>选修课</option></select>";
                        }else{
                            return "<select name=\"chooseCourseType\" class=\"form-control m-b\" style=\"width:100px;\" ><option value='0'>必修课</option><option value='1' selected>选修课</option></select>";
                        }
                    }
                },
                {
                    field : 'courseType',
                    title : '课程类型',
                    formatter: function (value, row, index) {
                        if(row.courseType==0){
                            return "<select name=\"courseType\" class=\"form-control m-b\" style=\"width:120px;\" ><option value='0' selected>公共课程</option><option value='1'>专业课程</option></select>";
                        }else{
                            return "<select name=\"courseType\" class=\"form-control m-b\" style=\"width:120px;\" ><option value='0'>公共课程</option><option value='1' selected>专业课程</option></select>";
                        }
                    }
                },
                {
                    field : 'studyScore',
                    title : '学分',
                    formatter: function (value, row, index) {
                        return "<input class=\"coursenum\" name='studyScore' type='text' onfocus=this.blur() value='"+value+"'>";
                    }
                },
                {
                    field : 'studyTime',
                    title : '总学时',
                    formatter: function (value, row, index) {
                        return "<input class=\"coursenum\" name='studyTime' type='text' onfocus=this.blur() value='"+value+"'>";
                    }
                },
                {
                    field : 'term',
                    title : '学期',
                    formatter: function (value, row, index) {
                        if(row.term==0){
                            return "<select name=\"term\" class=\"form-control m-b\" style=\"width:100px;\" ><option value='0' selected>第一学期</option><option value='1'>第二学期</option></select>";
                        }else{
                            return "<select name=\"term\" class=\"form-control m-b\" style=\"width:100px;\" ><option value='0'>第一学期</option><option value='1' selected>第二学期</option></select>";
                        }
                    }
                },
                {
                    field : 'assessWay',
                    title : '考核方式',
                    formatter: function (value, row, index) {
                        if(row.assessWay==0){
                            return "<select name=\"assessWay\" class=\"form-control m-b\" style=\"width:100px;\" ><option value='0' selected>考试</option><option value='1'>考察</option></select>";
                        }else{
                            return "<select name=\"assessWay\" class=\"form-control m-b\" style=\"width:100px;\" ><option value='0'>考试</option><option value='1' selected>考察</option></select>";
                        }
                    }
                }]
        };
        $.table.init(options);
    });

   function submitHandler() {
        var len = $("#bootstrap-table :input:checkbox:checked").length;
        if(len==0){
            alert("请选择课程");
            return false;
        }
        $.modal.confirm("确认要修改吗?", function() {
            var Check = $("table input[type=checkbox]:checked");
            var cons = new Array();
            Check.each(function () {//遍历
                var con = {};
                var row = $(this).parent("td").parent("tr");//获取选中行
                // var studyScore = row.find("[name='studyScore']").html();//获取name='Sid'的值
                con["planId"]=$("#planId").val();
                con["courseId"] = row.find("[name='id']").val();
                con["chooseCourseType"]  = row.find("[name='chooseCourseType']").val();
                con["courseType"]  = row.find("[name='courseType']").val();
                con["studyScore"]  = row.find("[name='studyScore']").val();
                con["studyTime"]  = row.find("[name='studyTime']").val();
                con["term"]  = row.find("[name='term']").val();
                con["assessWay"]  = row.find("[name='assessWay']").val();

                con["planName"]  = $("#planName").val();
                con["majorId"]  = $("#majorId").val();
                con["version"]  = $("#version").val();
                con["beginEffectiveTime"]  = $("#beginEffectiveTime").val();
                cons.push(con);
            });
            var form1 = new FormData(document.getElementById("formId"));
            $.ajax({
                url:prefix+"/editAddPlanList",
                type:"post",
                // data:form,
                data:JSON.stringify(cons),
                cache: false,
                processData: false,
                contentType: "application/json;charset=utf-8",
                // contentType: false,
                success:function(data){
                    if(data.code==500){
                        $.modal.msgError(data.msg)
                    }
                    if(data.code==0){
                        $.modal.msgReload(data.msg,'success')
                       /* $.modal.msgSuccess(data.msg)
                        var int=self.setInterval(function(){  // 这个方法是说在延迟两秒后执行大括号里的方法
                            $.modal.reload();
                        },1000) //这里2000代表两秒*/

                    }
                }
            });

        });

        }
</script>
</body>
</html>